import { scene } from './utils/init'
import * as THREE from 'three'
import { guiChangeColor } from './utils/gui'

function initBase() {
  const geometry = new THREE.SphereGeometry(1, 32, 16)

  const textureLoader = new THREE.TextureLoader()
  const texture = textureLoader.load('texture/one/basecolor.jpg')
  texture.colorSpace = THREE.SRGBColorSpace
  const transTextureLoader = new THREE.TextureLoader()
  const transTexture = transTextureLoader.load('texture/one/opacity.jpg')

  const aoTextureLoader = new THREE.TextureLoader()
  const aoTexture = aoTextureLoader.load('texture/one/ambientOcclusion.jpg')

  // 使用新的lamber网格材质
  const material = new THREE.MeshLambertMaterial({ 
    map: texture,
    // alphaMap: transTexture,
    // transparent: true,
    aoMap: aoTexture
  })

  const mesh = new THREE.Mesh(geometry, material)
  console.log(mesh, 'mesh');
  mesh.geometry.setAttribute('uv2', new THREE.Float32BufferAttribute(mesh.geometry.attributes.uv.array, 2))
  scene.add(mesh)
}

// 创建光源
function createLight () {
    // 环境光: 无方向，照亮场景中所有受光照影响的物体
    const light = new THREE.AmbientLight(0xffffff) // 柔和的白光
    scene.add(light)
    // 平行光：从一个方向照射过来的
    const direction = new THREE.DirectionalLight(0xffffff, 2)
    direction.position.set(2, 3, 2)
    scene.add(direction)
    // 平行光辅助对象
    // 参数1：平行光对象， 参数2：模拟平行光光源
    const helper = new THREE.DirectionalLightHelper(direction, .5)
    scene.add(helper)
}

initBase()
createLight()